package com.cashmama.market.api.domain.handler;

import com.cashmama.market.api.domain.vo.order.OrderStatusBriefInfo;
import com.cashmama.market.api.domain.vo.order.OrderStatusDTO;
import com.cashmama.market.api.infras.enums.JumpRouterEnum;
import com.cashmama.market.api.infras.enums.order.BorrowStatusEnum;
import com.qianli.cashmama.trade.common.enums.TradeStatusEnum;
import org.springframework.stereotype.Service;

/**
 * @program: market-api
 * @description
 * @author: frank
 * @create: 2019-12-26 16:11
 **/
@Service
public class OrderStatusHandler {

    public OrderStatusBriefInfo getOrderStatusForApp(OrderStatusDTO orderStatusDTO) {
        OrderStatusBriefInfo orderStatusBriefInfo = new OrderStatusBriefInfo();
        String buttonJumpUrl = JumpRouterEnum.ORDER_DETAIL.getJumpUrl() + "?tradeNo=" + orderStatusDTO.getTradeNo();
        BorrowStatusEnum borrowStatus = BorrowStatusEnum.PENDING;
        TradeStatusEnum tradeStatusEnum = orderStatusDTO.getTradeStatusEnum();
        orderStatusBriefInfo.setBorrowStatusEnum(borrowStatus);
        orderStatusBriefInfo.setJumpUrl(buttonJumpUrl);

        //待打款(打款中)
        if (tradeStatusEnum.equals(TradeStatusEnum.LOAN_WAITTING)) {
            orderStatusBriefInfo.setBorrowStatusEnum(BorrowStatusEnum.TRANSFERRING);
            orderStatusBriefInfo.setJumpUrl(buttonJumpUrl);
            return orderStatusBriefInfo;
        }

        //订单关闭
        boolean completed = tradeStatusEnum.equals(TradeStatusEnum.NORMAL_REPAYMENT) ||
                tradeStatusEnum.equals(TradeStatusEnum.EARLY_REPAYMENT) ||
                tradeStatusEnum.equals(TradeStatusEnum.OVERDUE_REPAYMENT) ||
                tradeStatusEnum.equals(TradeStatusEnum.MANUAL_CLOSED);
        if (completed) {
            orderStatusBriefInfo.setBorrowStatusEnum(BorrowStatusEnum.COMPLETED);
            orderStatusBriefInfo.setJumpUrl(buttonJumpUrl);
            return orderStatusBriefInfo;
        }

        //订单拒绝
        if (tradeStatusEnum.equals(TradeStatusEnum.AUDIT_REJECT)) {
            orderStatusBriefInfo.setBorrowStatusEnum(BorrowStatusEnum.REFUSE);
            orderStatusBriefInfo.setJumpUrl(buttonJumpUrl);
            return orderStatusBriefInfo;
        }

        //待提现
        if (tradeStatusEnum.equals(TradeStatusEnum.PENDING_WITHDRAWAL)) {
            orderStatusBriefInfo.setBorrowStatusEnum(BorrowStatusEnum.PENDING_WITHDRAWAL);
            return orderStatusBriefInfo;
        }

        //放款失败
        if (TradeStatusEnum.PAY_RETRY.equals(tradeStatusEnum)) {
            orderStatusBriefInfo.setBorrowStatusEnum(BorrowStatusEnum.PENDING_FAILD);
            orderStatusBriefInfo.setJumpUrl(buttonJumpUrl);
            return orderStatusBriefInfo;
        }

        //待还款
        if (tradeStatusEnum.equals(TradeStatusEnum.REPAYMENT_WATTING)) {
            orderStatusBriefInfo.setBorrowStatusEnum(BorrowStatusEnum.REPAY);
            orderStatusBriefInfo.setJumpUrl(buttonJumpUrl);
            return orderStatusBriefInfo;
        }

        if (tradeStatusEnum.equals(TradeStatusEnum.OVERDUE)) {
            orderStatusBriefInfo.setBorrowStatusEnum(BorrowStatusEnum.OVER_DUE);
            orderStatusBriefInfo.setJumpUrl(buttonJumpUrl);
            return orderStatusBriefInfo;
        }
        return orderStatusBriefInfo;
    }
}
